#ifndef __DIR_H
#define __DIR_H
#include"global.h"
#include"fs.h"
#include"inode.h"
#include"ide.h"
#include"list.h"

#define FILE_NAME_MAX_LEN 24
#define DIR_ENTRY_PER_SECTOR 16
#define MAX_PATH_LEN 512

//size is 32
struct dir_entry{
	char name[FILE_NAME_MAX_LEN];
	uint32_t i_no;
	fs_type ft;
};

struct dir{
	struct winode* inode;
	uint32_t dir_pos;
	struct dir_entry dir_entrys[DIR_ENTRY_PER_SECTOR];
};

typedef struct {
	char path[MAX_PATH_LEN];
	struct dir* pdir;
	fs_type ft;
	bool is_path_valid;
}path_record;

void open_root_dir(struct partition* part);

struct dir* open_dir(struct partition* part,uint32_t i_no);

void close_dir(struct dir*);

bool dir_entry_insert_sync(struct partition*,struct dir*,struct dir_entry*,char*);

bool dir_entry_delete_sync(struct partition*,struct dir*,const char*,char*);

void create_dir_entry(const char* name,uint32_t i_no,fs_type ft,struct dir_entry* dir_e);

void get_dir_entry(struct partition* part,char* iobuffer,struct winode* wi,struct dir_entry* dir_e,int32_t i_no);

int32_t path_parse(const char* path,path_record* pr);

void get_parent_dir_entry(struct dir_entry* all_entrys,struct dir_entry* dir_e,uint32_t cnt);

struct dir_entry* sys_readdir(struct dir* dir);

void sys_rewinddir(struct dir* dir);

struct dir* sys_opendir(const char*);

int32_t sys_closedir(struct dir*);

int32_t sys_rmdir(const char* path);

#endif
